/**
 * Created by lxy_920912 on 27/03/2017.
 */
var permuteUnique = function(nums) {
    var list = [];
    nums.sort();
    backTrace(0);
    return list;

    function backTrace(start) {
        if(start >= nums.length){
            list.push([].concat(nums));
            return;
        }
        for(var i = start;i < nums.length;i++){
            if(nums[i] == nums[start] || nums[i] == nums[i-1]){
                continue;
            }else{
                swap(start,i);
                backTrace(start+1);
                swap(start,i);
            }
        }

    }
    function swap(i,j) {
        var temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }

};
console.log(permuteUnique([2,2,1,1]));